package cn.com.clearbus.mini.controller;



import cn.com.clearbus.mini.BaseController;
import cn.com.clearbus.mini.entity.MiniUser;
import cn.com.clearbus.mini.service.IMiniUserService;
import cn.com.clearbus.result.DynamicResult;
import cn.com.clearbus.result.ErrCode;
import cn.hutool.core.lang.Validator;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liuwz
 * @since 2019-10-14
 */
@RestController
@RequestMapping("/user")
public class MiniUserController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(MiniUserController.class);

    @Autowired
    IMiniUserService miniUserService;


    @PostMapping(value = "/isMember")
    @ApiOperation(value = "判断是否是会员", notes = "时间：2019-10-16 作者: 刘王震")
    public String isMember(@RequestBody MiniUser miniUser) {
        logger.info("接收到的请求参数信息为:"+miniUser);
        MiniUser member = miniUserService.isMember(miniUser);
        return member.toString();
    }

    @PostMapping(value = "/saveMember")
    @ApiOperation(value = "保存会员", notes = "时间：2019-10-16 作者: 刘王震")
    public DynamicResult saveMember(@RequestBody MiniUser miniUser) {
        logger.info("接收到的请求参数信息为:"+miniUser);
        //测试Email
        if (!Validator.isEmail(miniUser.getEmail())) {
            return new DynamicResult(ErrCode.FAILURE,"邮箱格式不正确");
        }
        DynamicResult dynamicResult = miniUserService.saveMember(miniUser);
        return dynamicResult;
    }

    @GetMapping(value = "/qrcode")
    @ApiOperation(value = "获取", notes = "时间：2019-10-16 作者: 刘王震")
    public DynamicResult qrcode(@RequestParam("qrcode") String qrcode) {

        return miniUserService.qrcode(qrcode);
    }


}
